package cn.yangyumanage.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;


import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.viewpager2.widget.ViewPager2;

import com.google.android.material.tabs.TabLayout;
import com.google.android.material.tabs.TabLayoutMediator;

import java.util.ArrayList;
import java.util.List;

import cn.yangyumanage.R;
import cn.yangyumanage.adapter.LeaveMessageVp2Adapter;

public class LeaveMessageFragment extends Fragment {

    private View view;
    private TabLayout tl_tab;
    private ViewPager2 vp2_leave_message;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_leave_message, container, false);
        initView();
        initData();
        return view;
    }

    public void initView() {
        tl_tab = view.findViewById(R.id.tl_tab);
        vp2_leave_message = view.findViewById(R.id.vp2_leave_message);
    }

    public void initData() {
        initFragment();
    }

    public void initFragment() {
        List<String> labelList = new ArrayList<>();
        List<Fragment> fragments = new ArrayList<>();
        fragments.add(new PassLeaveMessageFragment());
        fragments.add(new NotPassLeaveMessageFragment());
        fragments.add(new WaitLeaveMessageFragment());
        labelList.add("已通过审核");
        labelList.add("未通过审核");
        labelList.add("等待审核中");
        vp2_leave_message.setAdapter(new LeaveMessageVp2Adapter(getParentFragmentManager(), getLifecycle(), fragments));
        new TabLayoutMediator(tl_tab, vp2_leave_message, new TabLayoutMediator.TabConfigurationStrategy() {
            @Override
            public void onConfigureTab(@NonNull TabLayout.Tab tab, int position) {
                tab.setText(labelList.get(position));
            }
        }).attach();
    }
}